package cn.afactory.tygz.ui.base.views;

import android.content.Context;
import android.text.InputFilter;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.EditText;

/**
 * 监听粘贴
 * 
 * @author zhaocheng
 *
 */
//
public class PasteEditText extends EditText {

    private int maxLength = 500;
    // 系统常量
    // 粘贴
    private static final int ID_PASTE = android.R.id.paste;

    public PasteEditText(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public PasteEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public PasteEditText(Context context) {
        super(context);
    }

    @Override
    public boolean onTextContextMenuItem(int id) {
        if (id == ID_PASTE) {
            // 粘贴
            Log.d("DEBUG", "length------>");
            setFilters(new InputFilter[] { new InputFilter.LengthFilter(maxLength) });
        }
        return super.onTextContextMenuItem(id);
    }

    public void setMaxPasteTextLength(int length){
        this.maxLength = length;
    }
}
